<template>
  <div>
    <el-card class="box-card">
      <!-- 表头 -->
      <div slot="header" class="clearfix">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/home/leave' }">留言反馈</el-breadcrumb-item>
          <el-breadcrumb-item>评论留言</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <!-- 用户信息 -->
      <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
        <el-form-item label="用户昵称">
          <el-input v-model="formLabelAlign.userName" style="width:600px" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="手机号码">
          <el-input v-model="formLabelAlign.userPhone" style="width:600px" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="留言内容">
          <el-input type="textarea" autosize v-model="formLabelAlign.wordContent" style="width:600px" :disabled="true"></el-input>
          <el-button type="primary" style="margin-left:40px" @click="dialogVisible = true" :disabled='formLabelAlign.wordReply?true:false'>回复</el-button>
        </el-form-item>
      </el-form>
      <!-- 分隔线 -->
      <el-divider></el-divider>
      <!-- 评论回复的消息 -->
      <el-row>
        <el-col :span="20">
          <div class="size" style=" text-align: left;">{{formLabelAlign.wordReply}}</div>
        </el-col>
      </el-row>
    </el-card>
    <!-- 弹窗 -->
    <el-dialog title="留言回复" :visible.sync="dialogVisible" width="30%" >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="回复信息" prop="desc">
          <el-input
            type="textarea"
            v-model="ruleForm.desc"
            placeholder="输入内容限制50个字符"
            maxlength="50"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false, //弹窗默认关闭
      labelPosition: "left", //居左
      formLabelAlign: {},
      //   from表单验证消息
      ruleForm: {
        desc: ""
      },
      rules: {
        desc: [{ required: true, message: "请输入回复信息", trigger: "blur" }]
      }
    };
  },
  created() {
    this.$http.article
      .feedbackget({ yjLeaveWordId: this.$route.query.wordId })
      .then(res => {
        console.log("获取留言详情", res);
        this.formLabelAlign = res.result;
      });
    console.log("this.$route.query.id", this.$route.query.wordId);
  },
  methods: {
    backMessage() {
      console.log("回复消息");
    },
    // 是否关闭
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    // 弹窗信息
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        // 如果值匹配请求接口
        if (valid) {
          let param = {
            wordId: this.formLabelAlign.wordId,
            wordReply: this.ruleForm.desc,
            wordStatus: 2
          };
          console.log("获取信息", param);
          this.$http.article.feedbackupadte(param).then(res => {
            if (res.code == 200) this.$router.push("/home/leave");
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style lang="scss" scoped>
.bg {
  width: 100%;
  height: 100%;
  background-color: #f4f7fd;
  //   overflow: hidden;
}
.box-card {
  //   display: flex;
  //   justify-content: center;
  width: 98%;
  margin: 0 auto;
  margin-top: 10px;
}
.size {
  vertical-align: middle;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  box-sizing: border-box;
}
</style>